package com.example.xdemo.slice;

import com.example.xdemo.GridAbility;
import com.example.xdemo.LinearAbility;
import com.example.xdemo.LinearStickyScrollAbility;
import com.example.xdemo.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Button;
import ohos.agp.components.Component;

public class MainAbilitySlice extends AbilitySlice {
    private Button btn_abt_linear;
    private Button btn_abt_grid;
    private Button btn_abt_linear_sticky_scroll;
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        initView();
    }

   private void initView(){
       Intent intent = new Intent();
       btn_abt_linear = (Button)findComponentById(ResourceTable.Id_abt_main_button1);
       btn_abt_linear.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Operation operation = new Intent.OperationBuilder()
                        .withBundleName(getBundleName())
                        .withAbilityName(LinearAbility.class.getName())
                        .build();
                intent.setOperation(operation);
                startAbility(intent);
            }
        });

        btn_abt_grid = (Button)findComponentById(ResourceTable.Id_abt_main_button2);
        btn_abt_grid.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Operation operation = new Intent.OperationBuilder()
                        .withBundleName(getBundleName())
                        .withAbilityName(GridAbility.class.getName())
                        .build();
                intent.setOperation(operation);
                startAbility(intent);
            }
        });

        btn_abt_linear_sticky_scroll = (Button)findComponentById(ResourceTable.Id_abt_main_button3);
       btn_abt_linear_sticky_scroll.setClickedListener(new Component.ClickedListener() {
           @Override
           public void onClick(Component component) {
               Operation operation = new Intent.OperationBuilder()
                       .withBundleName(getBundleName())
                       .withAbilityName(LinearStickyScrollAbility.class.getName())
                       .build();
               intent.setOperation(operation);
               startAbility(intent);
           }
        });

   }
}
